#include <stdio.h>
#include <unistd.h>
#include <inttypes.h>
#include "BasicCom.pb.h"
#include "somb.h"

#include "example_producer.h"


static uint32_t eventloop = 0;
void basiccom_trigger_event_test()
{
    int ret;
    uint32_t loop=0,count=0;

    printf("input the count of events\n");
    scanf("%d",&count);
    printf("the count of events=%d\n",count);

    for(;loop<count;loop++)
    {
        st_basic_com_form_event EvtMsg = st_basic_com_form_event_init_zero;
        EvtMsg.id = eventloop;
        snprintf(EvtMsg.data,sizeof(EvtMsg.data),"event-%d",eventloop++);

        uint8_t *pBuffer= SOMB_ALLOC(st_basic_com_form_event_size);
        uint32_t BufferSize=st_basic_com_form_event_size;
        int32_t Error;

        Error = SOMB_MESSAGE_ENCODE(st_basic_com_form_event,&EvtMsg,pBuffer,&BufferSize) ;
        if( 0 != Error )
        {
            printf("#########basiccom message encode failed\n");
            SOMB_FREE(pBuffer);
            return ;
        }

        ret = i32SOMB_Event_Trigger(BASICCOM_SID_EVENT_TEST,pBuffer,BufferSize);
        if(ret != SOMB_OK)
        {
            printf("#########basiccom send event ServiceId(%08x) failed\n",BASICCOM_SID_EVENT_TEST);
            SOMB_FREE(pBuffer);
            return ;
        }
        else
        {
            printf("Producer Event  send:%s\n",EvtMsg.data);

        }
        
        SOMB_FREE(pBuffer);
        
    }
}
int32_t basiccom_event_on_listen_cb(uint32_t ServiceId,void**EvtData,uint32_t *EvtDataLen)
{
    /*if this function is called, that means some other consumer was listenning to BASICCOM_SID_EVENT_TEST*/
    printf("Event ServiceId=0x%08x was being listened \n", ServiceId);


    /*then , we should prepare the event data for the listener on their first listen action*/
    st_basic_com_form_event EvtMsg = st_basic_com_form_event_init_zero;
    EvtMsg.id = eventloop;
    snprintf(EvtMsg.data,sizeof(EvtMsg.data),"event-%d",eventloop++);

    /* prepare the memory space for the event data */
    *EvtData = SOMB_ALLOC(st_basic_com_form_event_size);
    if(NULL == *EvtData)
    {
        printf("### malloc failed\n");
        return SOMB_FAIL;
    }

    *EvtDataLen=st_basic_com_form_event_size;
    int32_t Error;

    Error = SOMB_MESSAGE_ENCODE(st_basic_com_form_event,&EvtMsg,*EvtData, EvtDataLen) ;
    if( 0 != Error )
    {
        printf("#########basiccom message encode failed\n");
        SOMB_FREE(*EvtData); // must free the data if error happened inner of callback 
        return SOMB_FAIL;
    }

    /*don't free the memory allocated by EvtData if return SOMB_OK, it will auto freed by somb*/
    return SOMB_OK;
}
void basiccom_method_service_provider(uint32_t handle,uint32_t ServiceId,void*MthReqData,uint32_t MthReqDataLen)
{
    printf("basiccom recv ServiceId=%08x handle=%08x datalen=%d\n",ServiceId,handle,MthReqDataLen);
    int32_t Error;
    int32_t ret;
    switch(ServiceId)
    {
        case BASICCOM_SID_METHOD_SETREQUST_TEST:
            {
                st_basic_com_form_setreq msg_setreq = st_basic_com_form_setreq_init_zero;

                //针对不定长的string类型数据，需要提前分配buffer
                uint8_t sng_string_recv_buf[16]={0};
                SOMB_INIT_BYTES_DECODE_BUFFER(msg_setreq.sng_string,sng_string_recv_buf,sizeof(sng_string_recv_buf));
                uint8_t sng_bytes_recv_buf[16]={0};
                SOMB_INIT_BYTES_DECODE_BUFFER(msg_setreq.sng_bytes,sng_bytes_recv_buf,sizeof(sng_bytes_recv_buf));
                uint8_t rep_string_recv_buf[16]={0};
                SOMB_INIT_BYTES_DECODE_BUFFER(msg_setreq.rep_string,rep_string_recv_buf,sizeof(rep_string_recv_buf));
                uint8_t rep_bytes_recv_buf[16]={0};
                SOMB_INIT_BYTES_DECODE_BUFFER(msg_setreq.rep_bytes,rep_bytes_recv_buf,sizeof(rep_bytes_recv_buf));

                //开始解码
                Error = SOMB_MESSAGE_DECODE(st_basic_com_form_setreq,&msg_setreq,MthReqData,MthReqDataLen);
                if(0 != Error)
                {
                    printf("basiccom method service decode ServiceId=%08x setReq Data failed\n",ServiceId);
                }
                else
                {
                    //打印解码后的数据
                    printf("basiccom recv:\n");
                    printf("sng_int32:%d %s\n",     msg_setreq.sng_int32,   msg_setreq.sng_int32==1?"OK":"NG");
                    printf("sng_int64:%" PRIu64 "%s\n",     msg_setreq.sng_int64,   msg_setreq.sng_int64==2?"OK":"NG");
                    printf("sng_uint32:%d %s\n",    msg_setreq.sng_uint32,  msg_setreq.sng_uint32==3?"OK":"NG");
                    printf("sng_uint64:%"PRIu64" %s\n",    msg_setreq.sng_uint64,  msg_setreq.sng_uint64==4?"OK":"NG");
                    printf("sng_sint32:%d %s\n",    msg_setreq.sng_sint32,  msg_setreq.sng_sint32==-5?"OK":"NG");
                    printf("sng_sint64:%"PRIu64" %s\n",    msg_setreq.sng_sint64,  msg_setreq.sng_sint64==-6?"OK":"NG");
                    printf("sng_bool:%d %s\n",      msg_setreq.sng_bool,    msg_setreq.sng_bool?"OK":"NG");
                    printf("sng_fixed32:%d %s\n",   msg_setreq.sng_fixed32, msg_setreq.sng_fixed32==8?"OK":"NG");
                    printf("sng_sfixed32:%d %s\n",  msg_setreq.sng_sfixed32,msg_setreq.sng_sfixed32==9?"OK":"NG");
                    printf("sng_float:%f \n",     msg_setreq.sng_float);

                    printf("sng_fixed64:%"PRIu64" %s\n",   msg_setreq.sng_fixed64, msg_setreq.sng_fixed64==11?"OK":"NG");
                    printf("sng_sfixed64:%"PRIu64" %s\n",  msg_setreq.sng_sfixed64,msg_setreq.sng_sfixed64==12?"OK":"NG");
                    printf("sng_double:%f\n",    msg_setreq.sng_double);

                    printf("sng_string:%s %s\n",    sng_string_recv_buf,   
                            (0==strcmp(sng_string_recv_buf,"14"))?"OK":"NG");
                    printf("sng_max_string:%s %s\n",msg_setreq.sng_max_string,   
                            (0==strcmp(msg_setreq.sng_max_string,"15"))?"OK":"NG");
                    printf("sng_fix_string:%s %s\n",msg_setreq.sng_fix_string,   
                            (0==strcmp(msg_setreq.sng_fix_string,"16"))?"OK":"NG");

                    printf("sng_bytes:%s %s\n",    sng_bytes_recv_buf,   
                            (0==strcmp(sng_bytes_recv_buf,"17"))?"OK":"NG");
                    printf("sng_max_bytes:%s %d %s\n",msg_setreq.sng_max_bytes.bytes,   
                            msg_setreq.sng_max_bytes.size,
                            (0==strcmp(msg_setreq.sng_max_bytes.bytes,"18"))?"OK":"NG");
                    printf("sng_fix_bytes:%s %s\n",msg_setreq.sng_fix_bytes,   
                            (0==strcmp(msg_setreq.sng_fix_bytes,"19"))?"OK":"NG");

                    if(msg_setreq.has_sng_submsg){
                        printf("sng_submsg:%d %s\n",msg_setreq.sng_submsg.sub_int32,   
                            (msg_setreq.sng_submsg.sub_int32 == 20)?"OK":"NG");
                    }
                    else{
                        printf("sng_submsg: NG\n");   
                    }

                    
                    printf("sng_enum:%d %s\n",msg_setreq.sng_enum,   
                            (msg_setreq.sng_enum == MyEnum_Truth)?"OK":"NG");

                    if(msg_setreq.has_sng_emptymsg){
                        printf("sng_submsg:%d %s\n",msg_setreq.sng_emptymsg.dummy_field,   "OK");
                    }
                    else{
                        printf("sng_emptymsg: NG\n");   
                    }

                    uint32_t loop = 0,loop_max=0;

                    printf("rep_int32(max=%d):",loop_max=msg_setreq.rep_int32_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%d ",msg_setreq.rep_int32[loop]);
                    }
                    printf("\n");

                    printf("rep_int64(max=%d):",loop_max=msg_setreq.rep_int64_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%"PRIu64" ",msg_setreq.rep_int64[loop]);
                    }
                    printf("\n");

                    printf("rep_uint32(max=%d):",loop_max=msg_setreq.rep_uint32_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%d ",msg_setreq.rep_uint32[loop]);
                    }
                    printf("\n");

                    printf("rep_uint64(max=%d):",loop_max=msg_setreq.rep_uint64_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%"PRIu64" ",msg_setreq.rep_uint64[loop]);
                    }
                    printf("\n");

                    printf("rep_sint32(max=%d):",loop_max=msg_setreq.rep_sint32_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%d ",msg_setreq.rep_sint32[loop]);
                    }
                    printf("\n");

                    printf("rep_sint64(max=%d):",loop_max=msg_setreq.rep_sint64_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%"PRIu64" ",msg_setreq.rep_sint64[loop]);
                    }
                    printf("\n");

                    //bool
                    printf("rep_bool(max=%d):",loop_max=msg_setreq.rep_bool_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%d ",msg_setreq.rep_bool[loop]);
                    }
                    printf("\n");

                    //fixed32
                    printf("rep_fixed32(max=%d):",loop_max=msg_setreq.rep_fixed32_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%d ",msg_setreq.rep_fixed32[loop]);
                    }
                    printf("\n");
                    //sfixed32
                    printf("rep_sfixed32(max=%d):",loop_max=msg_setreq.rep_sfixed32_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%d ",msg_setreq.rep_sfixed32[loop]);
                    }
                    printf("\n");
                    //float
                    printf("rep_float(max=%d):",loop_max=msg_setreq.rep_float_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%f ",msg_setreq.rep_float[loop]);
                    }
                    printf("\n");
                    //fixed64
                    printf("rep_fixed64(max=%d):",loop_max=msg_setreq.rep_fixed64_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%"PRIu64" ",msg_setreq.rep_fixed64[loop]);
                    }
                    printf("\n");
                    //sfixed64
                    printf("rep_sfixed64(max=%d):",loop_max=msg_setreq.rep_sfixed64_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%"PRIu64" ",msg_setreq.rep_sfixed64[loop]);
                    }
                    printf("\n");
                    //double
                    printf("rep_double(max=%d):",loop_max=msg_setreq.rep_double_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%f ",msg_setreq.rep_double[loop]);
                    }
                    printf("\n");

                    //rep_string
                    printf("rep_string:%s %s\n",    rep_string_recv_buf,   
                            (0==strcmp(rep_string_recv_buf,"44"))?"OK":"NG");
                    //rep_max_string
                    printf("rep_max_string(max=%d):",loop_max=msg_setreq.rep_max_string_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%d,%s ",loop,msg_setreq.rep_max_string[loop]);
                    }
                    printf("\n");

                    //rep_fix_string
                    printf("rep_fix_string(max=%d):",loop_max=msg_setreq.rep_fix_string_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%d,%s ",loop,msg_setreq.rep_fix_string[loop]);
                    }
                    printf("\n");

                    //rep_bytes
                    printf("rep_bytes:%s %s\n",    rep_bytes_recv_buf,   
                            (0==strcmp(rep_bytes_recv_buf,"47"))?"OK":"NG");
                    //rep_max_bytes
                    printf("rep_max_bytes(max=%d):",loop_max=msg_setreq.rep_max_bytes_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%d,%d,%s ",loop,
                                msg_setreq.rep_max_bytes[loop].size,
                                msg_setreq.rep_max_bytes[loop].bytes);
                    }
                    printf("\n");
                    //rep_fix_bytes
                    printf("rep_fix_bytes(max=%d):",loop_max=msg_setreq.rep_fix_bytes_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%d,%s ",loop,msg_setreq.rep_fix_bytes[loop]);
                    }
                    printf("\n");

                    //rep_submsg
                    printf("rep_submsg(max=%d):",loop_max=msg_setreq.rep_submsg_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%d,%d ",loop,msg_setreq.rep_submsg[loop].sub_int32);
                    }
                    printf("\n");

                    //rep_enum
                    printf("rep_enum(max=%d):",loop_max=msg_setreq.rep_enum_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%d,%d ",loop,msg_setreq.rep_enum[loop]);
                    }
                    printf("\n");
                    //rep_emptymsg
                    printf("rep_emptymsg(max=%d):",loop_max=msg_setreq.rep_emptymsg_count);
                    for(loop=0;loop<loop_max;loop++)
                    {
                        printf("%d,%c ",loop,msg_setreq.rep_emptymsg[loop].dummy_field);
                    }
                    printf("\n");

                    //oneof
                    printf("oneof =%d\n",msg_setreq.which_oneof_data);
                    switch(msg_setreq.which_oneof_data)
                    {
                        case st_basic_com_form_setreq_oneof_msg1_tag:
                            {
                            SubMessage *pSubMsg = &(msg_setreq.oneof_data.oneof_msg1);
                            printf("oneof msg1:%d %s\n",pSubMsg->sub_int32,(60 == pSubMsg->sub_int32)?"OK":"NG");
                            }
                            break;
                        case st_basic_com_form_setreq_oneof_msg2_tag:
                            {
                            EmptyMessage *pSubMsg = &(msg_setreq.oneof_data.oneof_msg2);
                            printf("oneof msg2:%d %s\n",pSubMsg->dummy_field,(61 == pSubMsg->dummy_field)?"OK":"NG");
                            }
                            break;
                        case st_basic_com_form_setreq_static_msg_tag:
                            {
                            SubMessage2 *pSubMsg = &(msg_setreq.oneof_data.static_msg);
                            printf("oneof msg3:%d %s\n",pSubMsg->sub_int32,(63 == pSubMsg->sub_int32)?"OK":"NG");
                            }
                            break;
                        default:
                            printf("oneof =%d, doesn't supported\n",msg_setreq.which_oneof_data);
                            break;
                    }

                }

            }
            break;
        case BASICCOM_SID_METHOD_REQUEST_RESPONSE_TEST1:
            {
                st_basic_com_form_req msgreq = st_basic_com_form_req_init_zero;
                uint8_t req_buffer[16]={0};
                SOMB_INIT_BYTES_DECODE_BUFFER(msgreq.req_data,req_buffer,sizeof(req_buffer));
                //开始解码
                Error = SOMB_MESSAGE_DECODE(st_basic_com_form_req,&msgreq,MthReqData,MthReqDataLen);
                if(0 != Error)
                {
                    printf("basiccom method service decode ServiceId=%08x Request Data failed\n",ServiceId);
                }
                else
                {
                    printf("Producer recv TEST1:%d %s\n",msgreq.req_int32,req_buffer);

                    
                    //回复response
                    //将response结构体赋值
                    st_basic_com_form_resp msgresp = st_basic_com_form_resp_init_zero;
                    msgresp.resp_int32 = msgreq.req_int32;
                    msgresp.resp_data.size = snprintf(msgresp.resp_data.bytes,16,"response1-%d",msgresp.resp_int32);
                    printf("Producer response TEST1:%d %s\n",msgresp.resp_data.size,msgresp.resp_data.bytes);
                    
                    //准备resp buffer用于保存将response数据encode后的 数据
                    //因为st_basic_com_form_resp在proto文件的定义，不存在动态变量，所以此结构体体是静态大小的
                    //所以，可以使用xxx_size作为buffer的分配size
                    uint8_t *resp_buffer = SOMB_ALLOC(st_basic_com_form_resp_size);
                    uint32_t resp_buffer_size = st_basic_com_form_resp_size;
                    Error = SOMB_MESSAGE_ENCODE(st_basic_com_form_resp,&msgresp,resp_buffer,&resp_buffer_size);
                    if( 0 != Error )
                    {
                        printf("######producer response message encode failed\n");
                        SOMB_FREE(resp_buffer);
                        exit(0);
                    }
                    //发送resp_buffer
                    ret = i32SOMB_Method_Complete(handle,ServiceId,resp_buffer,resp_buffer_size);
                    if(SOMB_OK != ret)
                    {
                        printf("######consumer complete ServiceId(%08x) failed\n",ServiceId);
                        SOMB_FREE(resp_buffer);
                        exit(0);
                    }
                    SOMB_FREE(resp_buffer);
                }
            }
            break;
        case BASICCOM_SID_METHOD_REQUEST_RESPONSE_TEST2:
            {
                printf("Producer recv TEST2(without req data)\n");
                static uint32_t resp_int32 = 0;
                //回复response
                //将response结构体赋值
                st_basic_com_form_resp msgresp = st_basic_com_form_resp_init_zero;
                msgresp.resp_int32 = resp_int32;
                msgresp.resp_data.size = sprintf(msgresp.resp_data.bytes,"response2-%d",resp_int32++);
                
                //准备resp buffer用于保存将response数据encode后的 数据
                //因为st_basic_com_form_resp在proto文件的定义，不存在动态变量，所以此结构体体是静态大小的
                //所以，静态大小的结构体可以使用xxx_size作为buffer的静态分配
                uint8_t *resp_buffer = SOMB_ALLOC(st_basic_com_form_resp_size);
                uint32_t resp_buffer_size = st_basic_com_form_resp_size;
                Error = SOMB_MESSAGE_ENCODE(st_basic_com_form_resp,&msgresp,resp_buffer,&resp_buffer_size);
                if( 0 != Error )
                {
                    printf("######producer response message encode failed\n");
                    SOMB_FREE(resp_buffer);
                    exit(0);
                }
                //发送resp_buffer
                ret = i32SOMB_Method_Complete(handle,ServiceId,resp_buffer,resp_buffer_size);
                if(SOMB_OK != ret)
                {
                    printf("consumer complete ServiceId(%08x) failed\n",ServiceId);
                    SOMB_FREE(resp_buffer);
                    exit(0);
                }
                else
                {
                    printf("consumer complete ServiceId(%08x) with resp:%s\n",ServiceId,msgresp.resp_data.bytes);
                }
                SOMB_FREE(resp_buffer);

            }
            break;
        default:
            printf("######basiccom recv unsupported ServiceId=%08x handle=%08x\n",ServiceId,handle);
            break;
    }
}

void data_test_cb(uint32_t handle,uint32_t ServiceId,void*MthReqData,uint32_t MthReqDataLen)
{
    printf("data test:recv ServiceId=%08x handle=%08x datalen=%d\n",ServiceId,handle,MthReqDataLen);
    int32_t Error;
    int32_t ret;
    switch(ServiceId)
    {
        case BASICCOM_SID_METHOD_RRS_DATA_TEST:
        {
            st_rrs_data_test testmsg = st_rrs_data_test_init_zero;
            uint8_t decode_buffer[st_rrs_data_test_size];
            memset(decode_buffer,0,sizeof(decode_buffer));
            Error = SOMB_MESSAGE_DECODE(st_rrs_data_test,&testmsg,MthReqData,MthReqDataLen);
            if(0 != Error)
            {
                printf("rrs data test decode ServiceId=%08x failed\n",ServiceId);
            }
            else
            {
                st_rrs_data_test testmsg2 = st_rrs_data_test_init_zero;
                testmsg2.i32data = testmsg.i32data;
                uint8_t encode_buffer[st_rrs_data_test_size];
                uint32_t encode_buffer_size = st_rrs_data_test_size;
                memset(encode_buffer,0,sizeof(encode_buffer));
                Error = SOMB_MESSAGE_ENCODE(st_rrs_data_test,&testmsg2,encode_buffer,&encode_buffer_size);
                if(0 != Error)
                {
                    printf("rrs data test encode ServiceId=%08x failed\n",ServiceId);
                }
                else {
                    ret = i32SOMB_Method_Complete(handle, ServiceId, encode_buffer, encode_buffer_size)         ;
                    if(0 != ret)
                    {
                        printf("rrs data test complete ServiceId=%08x failed\n",ServiceId);
                    }
                }


            }
        }
        break;
        case BASICCOM_SID_METHOD_RRA_DATA_TEST:
        {
            st_rra_data_test testmsg = st_rra_data_test_init_zero;
            uint8_t decode_buffer[st_rra_data_test_size];
            memset(decode_buffer,0,sizeof(decode_buffer));
            Error = SOMB_MESSAGE_DECODE(st_rra_data_test,&testmsg,MthReqData,MthReqDataLen);
            if(0 != Error)
            {
                printf("rra data test decode ServiceId=%08x failed\n",ServiceId);
            }
            else
            {
                st_rra_data_test testmsg2 = st_rra_data_test_init_zero;
                testmsg2.i32data = testmsg.i32data;
                uint8_t encode_buffer[st_rra_data_test_size];
                uint32_t encode_buffer_size = st_rra_data_test_size;
                memset(encode_buffer,0,sizeof(encode_buffer));
                Error = SOMB_MESSAGE_ENCODE(st_rra_data_test,&testmsg2,encode_buffer,&encode_buffer_size);
                if(0 != Error)
                {
                    printf("rra data test encode ServiceId=%08x failed\n",ServiceId);
                }
                else {
                    ret = i32SOMB_Method_Complete(handle, ServiceId, encode_buffer, encode_buffer_size)         ;
                    if(0 != ret)
                    {
                        printf("rra data test complete ServiceId=%08x failed\n",ServiceId);
                    }
                }


            }
        }
        break;
        case BASICCOM_SID_METHOD_SETR_DATA_TEST:
        {
            st_setr_data_test testmsg = st_setr_data_test_init_zero;
            uint8_t decode_buffer[st_setr_data_test_size];
            memset(decode_buffer,0,sizeof(decode_buffer));
            Error = SOMB_MESSAGE_DECODE(st_setr_data_test,&testmsg,MthReqData,MthReqDataLen);
            if(0 != Error)
            {
                printf("setr data test decode ServiceId=%08x failed\n",ServiceId);
            }
            else
            {
                printf("setr data test decode ServiceId=%08x success\ni32data=%d,fdata=%f\n",ServiceId,testmsg.i32data,testmsg.fdata);
            }
        }
        break;
        default:
            {
                printf("unsupport service id\n");

            }
        break;
    }
}

void event_data_test_fn()
{
    st_event_data_test testmsg = st_event_data_test_init_zero;
    uint8_t encode_buffer[st_event_data_test_size];
    memset(encode_buffer,0,sizeof(encode_buffer));
    uint32_t encode_buffer_size=st_event_data_test_size;

    int Error = SOMB_MESSAGE_ENCODE(st_event_data_test,&testmsg,encode_buffer,&encode_buffer_size);
    if( 0 != Error )
    {
        printf("#########event data test message encode failed\n");
        return ;
    }

    int ret = i32SOMB_Event_Trigger(BASICCOM_SID_EVENT_DATA_TEST,encode_buffer,encode_buffer_size);
    if(ret != SOMB_OK)
    {
        printf("#########event data test send  failed\n");
        return ;
    }
    else
    {
        printf("event data test send:%d\n",testmsg.i32data);
    }


}


void print_usage()
{
    printf("---------------------------\n");
    printf("1: trigger event test\n");
    printf("---------------------------\n");
}

int main(void)
{
    uint32_t SubNsId;
    int32_t ret = i32SOMB_SubNs_Init(&SubNsId);
    if(SOMB_OK != ret)
    {
        printf("example_producer somb sub ns init failed\n");
        return -1;
    }
    printf("SubNs=%d SOMB Init success\n",SubNsId);

    void**Instance = NULL;
    Instance = vSOMB_Service_Instance_New();
    if(NULL == Instance)
    {
        printf("basiccom new service instance failed");
        return -1;
    }


    ret = i32SOMB_Service_Add(Instance,BASICCOM_SID_METHOD_SETREQUST_TEST,\
            SOMB_SVC_TYPE_METHOD,basiccom_method_service_provider);

    ret |= i32SOMB_Service_Add(Instance,BASICCOM_SID_METHOD_REQUEST_RESPONSE_TEST1,\
            SOMB_SVC_TYPE_METHOD,basiccom_method_service_provider);

    ret |= i32SOMB_Service_Add(Instance,BASICCOM_SID_METHOD_REQUEST_RESPONSE_TEST2,\
            SOMB_SVC_TYPE_METHOD,basiccom_method_service_provider);

    ret |= i32SOMB_Service_Add(Instance, BASICCOM_SID_EVENT_TEST,\
            SOMB_SVC_TYPE_EVENT, basiccom_event_on_listen_cb);

    //data test
    ret |= i32SOMB_Service_Add(Instance,BASICCOM_SID_METHOD_RRS_DATA_TEST,\
            SOMB_SVC_TYPE_METHOD,data_test_cb);
    ret |= i32SOMB_Service_Add(Instance,BASICCOM_SID_METHOD_RRA_DATA_TEST,\
            SOMB_SVC_TYPE_METHOD,data_test_cb);
    ret |= i32SOMB_Service_Add(Instance,BASICCOM_SID_METHOD_SETR_DATA_TEST,\
            SOMB_SVC_TYPE_METHOD,data_test_cb);
    ret |= i32SOMB_Service_Add(Instance,BASICCOM_SID_EVENT_DATA_TEST,\
            SOMB_SVC_TYPE_EVENT,NULL);
    if(SOMB_OK != ret)
    {
        printf("basiccom somb add service failed\n");
        return -1;
    }


    ret = i32SOMB_Service_Instance_Deploy(Instance);
    if(SOMB_OK != ret)
    {
        printf("basiccom somb service deploy failed\n");
        return -1;
    }

    ret = i32SOMB_Service_Instance_Destroy(Instance);
    if(SOMB_OK != ret)
    {
        printf("basiccom somb service destory failed\n");
        return -1;
    }

    bool keep=false;
    while(1)
    {
        if(!keep)
            print_usage();

        printf("chose your test index:\n");
        int cmd;
        scanf("%d",&cmd);
        printf("your chose is %d \n",cmd);
        keep = false;
        switch(cmd)
        {
            case 1:
                basiccom_trigger_event_test();
                break;
            case 2:
                event_data_test_fn();
                break;
        }
    }

    return 0;
}
